package com.tanhua.server.service;

import com.alibaba.fastjson.JSON;
import com.tan.model.domain.ErrorResult;
import com.tanhua.commons.utils.Constants;
import com.tanhua.server.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserFreezeService {

    @Autowired
    RedisTemplate<String,String> redisTemplate;
    //判断用户是否冻结，已冻结抛出异常
    /**
     * 冻结范围+用户id
     * freezingRange,冻结范围，1为冻结登录，2为冻结发言，3为冻结发布动态
     * */
    public void freeze(String status,Long userId) {
        String Key= Constants.USER_FREEZE+userId;
     String value =   redisTemplate.opsForValue().get(Key);
     if(value!=null){
         Map map = JSON.parseObject(value, Map.class);
         String freezingRange = (String) map.get("freezingRange");
         if(freezingRange.equals(status)){
             throw new BusinessException(ErrorResult.builder().errMessage("您已被冻结").build());
         }



     }






    }
}
